// custom-tab-bar/index.js
import {
    storeBindingsBehavior
} from 'mobx-miniprogram-bindings'
import {
    store
} from '../store/index'

Component({
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: ['active', 'numA'],
        actions: ['changeActive']
    },
    /**
     * 组件的属性列表
     */
    properties: {

    },
    lifetimes: {
        attached() {
            console.log(this.data.numA)
            this.setData({
                "list[2].info": this.data.numA
            })
        }
    },
    observers: {
        numA(newValue) {
            this.setData({
                "list[2].info": newValue
            })
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        list: [{
            "text": "首页",
            "pagePath": "/pages/home/home",
            "iconPath": "/images/home.png",
            "selectedIconPath": "/images/home-active.png"
        }, {
            "text": "分类",
            "pagePath": "/pages/classify/classify",
            "iconPath": "/images/classify.png",
            "selectedIconPath": "/images/classify-active.png",
           
        }, {
            "text": "购物车",
            "pagePath": "/pages/car/car",
            "iconPath": "/images/car.png",
            "selectedIconPath": "/images/car-active.png",
            info: 0
        }, {
            "text": "用户",
            "pagePath": "/pages/user/user",
            "iconPath": "/images/user.png",
            "selectedIconPath": "/images/user-active.png"
        }],
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(event) {
            // console.log(event)
            // event.detail 的值为当前选中项的索引
            this.changeActive(event.detail)

            wx.switchTab({
                url: this.data.list[event.detail].pagePath,
            })
        },
    },
})